package com.hornsun.client.discover.information.service;

import com.hornsun.client.discover.information.dto.InformationDTO;
import com.hornsun.domain.dbo.Information;
import com.hornsun.repository.InformationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 编译中... on 2018/2/26.
 */
@Service
public class InformationService {
    @Autowired
    private InformationRepository informationRepository;

    public InformationDTO getInformationByType(String typeid,int page){
        List<Information> recommendList = informationRepository.getRecommendInformationByType(typeid);
        List<Information> list;
        if(recommendList.size()==0){
            recommendList = informationRepository.getLastInformationByType(typeid);
            list=informationRepository.getInformationExLast(typeid,page,recommendList.get(0).getInformationGuid());
        }else {
            list = informationRepository.getInformationByTypeNotRecommend(typeid,page);
        }
        InformationDTO informationDTO = new InformationDTO();
        informationDTO.setRecommendInformation(recommendList.get(0));
        informationDTO.setInformationList(list);
        return informationDTO;
    }




}
